<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


/**
 * Description of members_model
 *
 * @author Administrator
 */
class Members_model extends CI_Model {
    const DB = 'members';
    /*
     * 获得用户的信息
     * @var int uid 用户id
     * return object
     */
    public function lists($where = array(),$select = '*')
    {
        foreach($where as $id=>$item){
            $this->db->where($id,$item);	
        }
	$this->db->select($select);
	$this->db->from(self::DB);
	$query = $this->db->get();
	return $query->result();
    }
    /*
     * 统计用户信息
     * @var int uid 用户id
     * return object
     */
    public function count($where = array(),$select = '*')
    {
        foreach($where as $id=>$item){
            $this->db->where($id,$item);	
        }
	$this->db->select($select);
	$this->db->from(self::DB);
	$query = $this->db->get();
	return $query->result();
    }
    /*
     * 后台获得用户的列表
     * @var int uid 用户id
     * return object
     */
    public function admin_list($where = array(),$select = '*',$limit = false,$limit_number = false)
    {
        foreach($where as $id=>$item){
            $this->db->where($id,$item);	
        }
	$this->db->select($select);
	$this->db->from(self::DB);
        if($limit !== false)
	{
		if($limit_number !== false)
		{
			$this->db->limit($limit_number,$limit);
		}
		else
		{
			$this->db->limit($limit);
                }
        }
        $members = $this->db->dbprefix(self::DB);
        $user = $this->db->dbprefix('user');
        $this->db->join('user',"{$members}.uid={$user}.uid",'left');
	$query = $this->db->get();
	return $query->result();
    } 
    /*
     * 添加一个用户
     */
    public function add($data)
    {
        $this->db->insert(self::DB, $data); 
	return $this->db->insert_id();
    }
    
    /*
     * 修改用户信息
     */
    public function update($data,$uid)
    {
        $this->db->where('uid',$uid);
        return $this->db->update(self::DB,$data);
    }
    
    /*
     * 删除用户
     */
    public function del($uid)
    {
        $this->db->where('uid',$uid);
        return $this->db->delete(self::DB);
    }
}